package com.wangjie.simple;

/**
 * @author jieshao
 * @date 2022/8/2 20:34
 *
 * 求两个有序数组中的不同元素
 */
public class Test21 {
    public static void main(String[] args) {
        int[] arr1 = {0, 0, 2, 2, 5, 5, 10, 10};
        int[] arr2 = {0, 4, 4, 5, 10, 10};
        test(arr1, arr2);
    }

    public static void test(int[] nums1, int[] nums2) {
        int m = nums1.length;
        int n = nums2.length;
        int p1 = 0;
        int p2 = 0;
        int cur;
        long pre = Long.MAX_VALUE;
        while (p1 < m || p2 < n) {
            if (p1 == m) {
                cur = nums2[p2++];
            } else if (p2 == n) {
                cur = nums1[p1++];
            } else if (nums1[p1] < nums2[p2]) {
                cur = nums1[p1++];
            } else {
                cur = nums2[p2++];
            }
            if (pre != cur) {
                System.out.println(cur);
            }
            pre = cur;
        }
    }
}